package com.xian.hotels.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.xian.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.xian.hotels.domain.HotelRooms;
import com.xian.hotels.mapper.HotelsMapper;
import com.xian.hotels.domain.Hotels;
import com.xian.hotels.service.IHotelsService;

/**
 * 酒店信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-08
 */
@Service
public class HotelsServiceImpl implements IHotelsService 
{
    @Autowired
    private HotelsMapper hotelsMapper;

    /**
     * 查询酒店信息
     * 
     * @param hotelId 酒店信息主键
     * @return 酒店信息
     */
    @Override
    public Hotels selectHotelsByHotelId(Long hotelId)
    {
        return hotelsMapper.selectHotelsByHotelId(hotelId);
    }

    /**
     * 查询酒店信息列表
     * 
     * @param hotels 酒店信息
     * @return 酒店信息
     */
    @Override
    public List<Hotels> selectHotelsList(Hotels hotels)
    {
        return hotelsMapper.selectHotelsList(hotels);
    }

    /**
     * 新增酒店信息
     * 
     * @param hotels 酒店信息
     * @return 结果
     */
    @Transactional
    @Override
    public int insertHotels(Hotels hotels)
    {
        int rows = hotelsMapper.insertHotels(hotels);
        insertHotelRooms(hotels);
        return rows;
    }

    /**
     * 修改酒店信息
     * 
     * @param hotels 酒店信息
     * @return 结果
     */
    @Transactional
    @Override
    public int updateHotels(Hotels hotels)
    {
        hotelsMapper.deleteHotelRoomsByHotelId(hotels.getHotelId());
        insertHotelRooms(hotels);
        return hotelsMapper.updateHotels(hotels);
    }

    /**
     * 批量删除酒店信息
     * 
     * @param hotelIds 需要删除的酒店信息主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteHotelsByHotelIds(Long[] hotelIds)
    {
        hotelsMapper.deleteHotelRoomsByHotelIds(hotelIds);
        return hotelsMapper.deleteHotelsByHotelIds(hotelIds);
    }

    /**
     * 删除酒店信息信息
     * 
     * @param hotelId 酒店信息主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteHotelsByHotelId(Long hotelId)
    {
        hotelsMapper.deleteHotelRoomsByHotelId(hotelId);
        return hotelsMapper.deleteHotelsByHotelId(hotelId);
    }

    /**
     * 新增房间信息信息
     * 
     * @param hotels 酒店信息对象
     */
    public void insertHotelRooms(Hotels hotels)
    {
        List<HotelRooms> hotelRoomsList = hotels.getHotelRoomsList();
        Long hotelId = hotels.getHotelId();
        if (StringUtils.isNotNull(hotelRoomsList))
        {
            List<HotelRooms> list = new ArrayList<HotelRooms>();
            for (HotelRooms hotelRooms : hotelRoomsList)
            {
                hotelRooms.setHotelId(hotelId);
                list.add(hotelRooms);
            }
            if (list.size() > 0)
            {
                hotelsMapper.batchHotelRooms(list);
            }
        }
    }
}
